import uuid

from django.db import models
from django.contrib.postgres.fields import ArrayField

import django.utils.timezone as timezone

# Create your models here.
# 　CHANGELOG
''' 20250625
1. 质量相关数据
'''


class ComplaintModel(models.Model):
    '''
    存储 Complaint 的主数据
    '''
    info_category_choices = (
        ('idmi_crawled', 'idmi_crawled'),
        ('maixun_crawled', 'maixun_crawled'),
    )


    id = models.AutoField(primary_key=True)
    # 创建时间
    create_time = models.DateTimeField(
        verbose_name="create_time",
        editable=True,
        default=timezone.now
    )
    purchase_year = models.CharField(
        max_length=4,
        verbose_name="purchase_year",
        blank=True,
        null=True,
        default=''
    )
    info_category = models.CharField(
        max_length=20,
        verbose_name="info_category",
        blank=True,
        null=True,
        choices=info_category_choices,
        default='maixun_crawled'
    )
    URL = models.CharField(
        max_length=400,
        verbose_name='URL',
        null=True,
        blank=True,
        default=''
    )
    FLAG_function_group_problem = models.BooleanField(
        verbose_name='FLAG_function_group_problem'
    )
    OEM_src = models.CharField(
        max_length=50, verbose_name='OEM_src',
        null=True, blank=True, default=''
    )
    ModelName_src = models.CharField(
        max_length=50, verbose_name='ModelName_src',
        null=True, blank=True, default=''
    )
    vehicle_line_src = models.CharField(
        max_length=50, verbose_name='vehicle_line_src',
        null=True, blank=True, default=''
    )
    # FLAG_brand_model_convert = models.BooleanField(
    #     verbose_name='FLAG_brand_model_convert',
    #     default=False
    # )
    OEM = models.CharField(
        max_length=50, verbose_name='OEM',
        null=True, blank=True, default=''
    )
    ModelName = models.CharField(
        max_length=50, verbose_name='ModelName',
        null=True, blank=True, default=''
    )
    vehicle_line = models.CharField(
        max_length=50, verbose_name='vehicle_line',
        null=True, blank=True, default=''
    )
    url_unique = models.CharField(
        max_length=400, verbose_name='url_unique',
        null=True, blank=True, default=''
    )
    title_zh = models.TextField(
        max_length=400, verbose_name='title_zh',
        null=True, blank=True, default=''
    )
    text_zh = models.TextField(
        max_length=1000, verbose_name='text_zh',
        null=True, blank=True, default=''
    )
    title_en = models.TextField(
        max_length=2000, verbose_name='title_en',
        null=True, blank=True, default=''
    )
    text_en = models.TextField(
        max_length=5000, verbose_name='text_en',
        null=True, blank=True, default=''
    )

    websites = models.CharField(
        max_length=50, verbose_name='websites',
        null=True, blank=True, default=''
    )

    # 下面是脉讯数据对应的字段
    maixun_author_location = models.CharField(
        max_length=50, verbose_name='maixun_author_location',
        null=True, blank=True, default=''
    )
    maixun_domain = models.CharField(
        max_length=50, verbose_name='maixun_domain',
        null=True, blank=True, default=''
    )
    maixun_fid = models.IntegerField(
        verbose_name='maixun_fid',
        default=0
    )

    def __str__(self):
        return self.title_zh


    class Meta:
        db_table = 'complaint'
        verbose_name = 'complaint'
        ordering = ['-id']
        abstract = False


class ComplaintFunctionGroupProblemModel(models.Model):
    complaint = models.ForeignKey(
        ComplaintModel,
        on_delete=models.CASCADE,
        verbose_name='Complaint',
        related_name='Complaint'
    )
    quality_1_int_value = models.IntegerField(
        verbose_name='quality_1_int_value',
        null=False,
        blank=False,
        default=-1
    )
    quality_2_int_value = models.IntegerField(
        verbose_name='quality_2_int_value',
        null=False,
        blank=False,
        default=-1
    )
    quality_3_int_value = models.IntegerField(
        verbose_name='quality_3_int_value',
        null=False,
        blank=False,
        default=-1
    )
    content_list_zh = ArrayField(
        models.CharField(
            max_length=500,
            verbose_name='content_list_zh',
            null=True,
            blank=True,
            default=''
        )
    )
    content_list_en = ArrayField(
        models.CharField(
            max_length=500,
            verbose_name='content_list_en',
            null=True,
            blank=True,
            default=''
        )
    )
    sentiment = models.IntegerField(
        verbose_name='sentiment',
        choices=[
            (1, 1),
            (2, 2),
            (3, 3),
            (4, 4),
            (5, 5),
        ],
        default=3
    )


    def __str__(self):
        return f"{self.complaint.id}"

    class Meta:
        db_table = 'complaintres'
        verbose_name = 'complaintres'
        ordering = ['-id']
        abstract = False


